package com.mxpio.erp.plan.service.impl;

import com.mxpio.erp.common.enums.OrderStatusEnums;
import com.mxpio.erp.common.plan.entity.SalePrediction;
import com.mxpio.erp.common.plan.service.SalePredictionService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.security.util.SecurityUtils;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class SalePredictionServiceImpl extends BaseServiceImpl<SalePrediction> implements SalePredictionService {
    @Override
    @Transactional
    public Result<SalePrediction> updateBpmnStatus(SalePrediction salePrediction, OrderStatusEnums.BpmnStatus auditing) {
        salePrediction.setBpmnStatus(auditing.getStatusCode());
        if (auditing.getStatusCode().equals(OrderStatusEnums.BpmnStatus.AUDITED.getStatusCode())){//审核通过时，才写入审核人和时间
            salePrediction.setReviewer(SecurityUtils.getLoginUsername());
            salePrediction.setReviewTime(new Date());
        }
        this.update(salePrediction);
        return Result.OK(salePrediction);
    }

    @Override
    @Transactional
    public Result<SalePrediction> updateCloseStatus(SalePrediction salePrediction, OrderStatusEnums.CloseStatus closeStatus) {
        salePrediction.setCloseStatus(closeStatus.getStatusCode());
        this.update(salePrediction);
        return Result.OK(salePrediction);
    }
}
